new Vue({
    el: '#main',
    data: () => ({
        country_id:$('#country_id').val(),
        cotypename: [],//公司类型
        number: [],//员工数量
        countryname: [],//国家
        provinces: [],//省份
        city: [],//城市
        town: [],//镇
        managename: [],//业务员
        linkarr: [],//联系人
        linkindex: '',//编辑时索引
        linkfun: [],//联系类型
        bankarr: [],//银行
        bankindex: '',//银行索引
        banklist: [],//银行
        brancharr: [],//分公司
        branchindex: '',//分公司索引
        evaluatearr: [],//公司风评
        evaluateindex: '',//公司风评索引
        //提交的数据
        data: {
            type_id: '',//公司分类值
            saler_id: '',//业务员值
            name: '',//公司名称值
            address: {
                country_id: '',//国家选择的值
                province_id: '',//省份选择的值
                city_id: '',//城市选择的值
                town_id: '',//乡镇选择的值
            },
            addr: '',//详细地址的值
            zipcode: '',//邮编的值
            statuss: 'NORMAL',//状态的值
            attrval: {
                select: [],
                text: []
            },
            works: '1',
            remarks: '',
            regno: '',
            taxno: '',
            act: $('#act').val(),
            co_id: $('#company_id').val()
        },
        lang: '',//语言
        //公司属性
        attrarr: {
            select: [],
            text: []
        },
        isdisadble: false,
        companyname: '',//公司名称
        //联系人弹框
        linkdata: {
            name: '',//姓名
            is_main: '1',//是否主要
            position: '',//职务
            sex: 1,//性别
            linkfunid: '',//联系类型id
            linkval: '',//联系方式值
            linkarr: [],//联系方式
            iseditlianxi: 'a',
            isex: '1',
            lianxi_ids: [],
            biaozhi: '',
        },
        //银行弹框
        bankdata: {
            banks_id: '',//银行id
            bankname: '',//开户行
            account_name: '',//户名
            account_num: '',//账号
            is_main: '1',//是否主要
            biaozhi: '',
        },
        //分公司弹框
        branchdata: {
            name: '',//名称
            lock: '0',//是否锁定
            provinces: [],//省份
            city: [],//城市
            town: [],//乡镇
            country_id: '',//国家id
            province_id: '',//省份选择的值
            city_id: '',//城市选择的值
            town_id: '',//乡镇选择的值
            addr: '',//地址
            zipcode: '',//邮编
            works: '1',//员工数量
            regno: '',//营业号
            taxno: ''//税号
        },
        //公司风评弹框
        evaluatedata: {
            comment: '',
            score: '0',
        }
    }),
    mounted(){
        $('.loding').show();
        if ($('#company_id').val()) {
            //编辑
            var geturl = "/admin/customer/companyedit?company_id=" + $('#company_id').val() + '&status=' + $('#act').val();
        } else {
            //添加
            var geturl = "/admin/customer/companyadd?status=" + $('#act').val();
        }
        $.ajax({
            url: geturl,
            data: {
                getcompany: ''
            },
            type: 'post',
            success: (data) => {
                data = JSON.parse(data)
                if (data) {
                    $('.loding').hide();
                    this.cotypename = data.cotypename;//公司类型
                    this.countryname = data.countryname;//国家
                    this.number = data.works;//员工数量
                    this.lang = data.lang;//语言
                    if (data.info) {
                        this.data.type_id = data.info.type_id
                        this.data.saler_id = data.info.saler_id
                        this.data.works = data.info.works
                        this.data.name = data.info.name
                        this.data.remarks = data.info.remarks
                        this.data.regno = data.info.regno
                        this.data.taxno = data.info.taxno
                        this.data.address.country_id = data.info.country_id
                        this.data.addr = data.info.addr
                        this.data.zipcode = data.info.zipcode
                        this.data.statuss = data.info.status
                        var getadd = async () => {
                            await this.selchangefun('provinces', this.data.address.country_id, 1)
                            this.data.address.province_id = data.info.province_id
                            await this.selchangefun('city', this.data.address.province_id, 1)
                            this.data.address.city_id = data.info.city_id
                            await this.selchangefun('town', this.data.address.city_id, 1)
                            this.data.address.town_id = data.info.town_id
                        }
                        getadd()
                        //公司属性
                        data.info.typeselect.forEach(element => {
                            if (element.is_text) {
                                this.attrarr.select.push(element)
                                if (data.info.coattrdata.length)
                                    data.info.coattrdata.forEach((item) => {
                                        if (item.coattr_id == element.id) {
                                            this.data.attrval.select.push({
                                                key: element.content,
                                                id: element.id,
                                                val: item.content
                                            })
                                        }
                                    })
                                else {
                                    this.data.attrval.select.push({key: element.content, id: element.id, val: 0})
                                }
                            } else {
                                this.attrarr.text.push(element)
                                if (data.info.coattrdata.length)
                                    data.info.coattrdata.forEach((item) => {
                                        if (item.coattr_id == element.id) {
                                            this.data.attrval.text.push({key: element.id, val: item.content})
                                        }
                                    })
                                else {
                                    this.data.attrval.text.push({key: element.id, val: ''})
                                }
                            }
                        });
                    }
                }
            }
        });
        //联系人数据
        this.getbanklinkbrancheva('link', 'linkarr');
        //银行账户数据
        this.getbanklinkbrancheva('bank', 'bankarr');
        //分公司数据
        this.getbanklinkbrancheva('branch', 'brancharr');
        //公司风评数据
        this.getbanklinkbrancheva('evaluate', 'evaluatearr');
        //获取公司名称
        this.getcompany();
        //初始化联系人
        $('#linkman_Modal').on('hide.bs.modal', () => {
            $('.modal-body .alert').hide()
            $('.modal-body .alert p').html()
            this.linkdata = this.$options.data().linkdata
            localStorage.removeItem("model");
        })
        //初始化银行
        $('#bank_Modal').on('hide.bs.modal', () => {
            $('.modal-body .alert').hide()
            $('.modal-body .alert p').html()
            this.bankdata = this.$options.data().bankdata
            localStorage.removeItem("model");
        })
        //初始化分公司
        $('#branch_editModal').on('hide.bs.modal', () => {
            $('.modal-body .alert').hide()
            $('.modal-body .alert p').html()
            this.branchdata = this.$options.data().branchdata
            localStorage.removeItem("model");
        });
        //初始化风评
        $('#co_evaluate_Modal').on('hide.bs.modal', () => {
            $('.modal-body .alert').hide()
            $('.modal-body .alert p').html()
            this.evaluatedata = this.$options.data().evaluatedata
            localStorage.removeItem("model");
        })
    },
    methods: {
        formatUnit: formatUnit,
        //主公司的改变地址
        selchangefun(type, val, code){
            if (type == 'provinces') {
                this.changegsfun(code);//改变国家（获取对应的业务员）
            }
            return new Promise((res, rej) => {
                $.ajax({
                    url: '/admin/api/getprovinces',
                    type: 'post',
                    data: {
                        tables: type,
                        id: val
                    },
                    success: (data) => {
                        data = JSON.parse(data)
                        switch (type) {
                            case 'provinces':
                                this.provinces = data
                                this.city = []
                                this.town = []
                                this.data.address.province_id = ''
                                this.data.address.city_id = ''
                                this.data.address.town_id = ''
                                break;
                            case 'city':
                                this.city = data
                                this.town = []
                                this.data.address.city_id = ''
                                this.data.address.town_id = ''
                                break;
                            case 'town':
                                this.town = data
                                this.data.address.town_id = ''
                                break;
                        }
                        res()
                    }
                })
            })
        },
        //分公司改变地址
        selchangebranchfun(type, val){
            return new Promise((res, rej) => {
                $.ajax({
                    url: '/admin/api/getprovinces',
                    type: 'post',
                    data: {
                        tables: type,
                        id: val
                    },
                    success: (data) => {
                        data = JSON.parse(data)
                        switch (type) {
                            case 'provinces':
                                this.branchdata.provinces = data
                                this.branchdata.city = []
                                this.branchdata.town = []
                                this.branchdata.province_id = ''
                                this.branchdata.city_id = ''
                                this.branchdata.town_id = ''
                                break;
                            case 'city':
                                this.branchdata.city = data
                                this.branchdata.town = []
                                this.branchdata.city_id = ''
                                this.branchdata.town_id = ''
                                break;
                            case 'town':
                                this.branchdata.town = data
                                this.branchdata.town_id = ''
                                break;
                        }
                        res()
                    }
                })
            })
        },
        //改变公司类型，获取属性和业务员
        changegsfun(code){
            $.ajax({
                url: '/admin/api/getcoattr',
                type: 'post',
                data: {
                    cotype: this.data.type_id,//类型
                    lang: this.lang,//语言
                    country_id: this.data.address.country_id,
                },
                success: (data) => {
                    data = JSON.parse(data)
                    this.managename = data.managename; //业务员
                    //公司类型改变时才触发
                    if (parseInt(code) == 2) {
                        this.attrarr.select = []
                        this.data.attrval.select = []
                        this.attrarr.text = []
                        this.data.attrval.text = []
                        data.coattr.forEach(element => {
                            if (element.is_text) {
                                this.attrarr.select.push(element)
                                this.data.attrval.select.push({key: element.id, val: 0})
                            } else {
                                this.attrarr.text.push(element)
                                this.data.attrval.text.push({key: element.id, val: ''})
                            }
                        });
                    }
                }
            })
        },
        //切换标签
        changestatus(codestatus){
            this.data.statuss = codestatus
        },
        //tab标签切换点击 'link','linkarr'
        getbanklinkbrancheva(status, arrdata){
            var action = $('#act').val();
            $.ajax({
                url: '/admin/customer/' + action,
                data: {
                    status: status,//状态
                    company_id: $('#company_id').val(),//公司id
                    country_id: $('#country_id').val(),
                },
                type: 'post',
                success: (data) => {
                    data = JSON.parse(data);
                    if (status == 'link') {
                        //联系人
                        this.linkfun = data.linkfun;//联系类型
                    } else if (status == 'bank') {
                        //银行
                        this.banklist = data.bankdata;//银行
                    }
                    this[arrdata] = data.data
                }
            })
        },
        //所有数据的保存
        subfun(){
            this.isdisadble = true;
            this.data.linkarr=this.linkarr;//联系人
            this.data.bankarr=this.bankarr;//银行
            this.data.brancharr=this.brancharr;//分公司
            this.data.evaluatearr=this.evaluatearr;//风评
            $.ajax({
                url: '/admin/customer/' + $('#act').val(),
                type: 'post',
                data: this.data,
                success: (data) => {
                    data = JSON.parse(data)
                    change_mes_type('#headeralert', data.status)
                    $('#headeralert').show()
                    $('#headeralert p').html('*' + data.msg + '<br>')
                    this.isdisadble = false;
                }
            })
        },
        //返回列表页
        returnlist(){
            location.href = "/admin/customer/customercompany"
        },
        //获取公司名称
        getcompany(){
            var company_id = location.search;
            $.ajax({
                url: '/admin/api/getcompanyname' + company_id,
                type: 'post',
                success: (data) => {
                    this.companyname = data
                }
            })
        },
        //添加联系人
        addlinkman(){
            this.linkdata.biaozhi = 'linkmanadd';
        },
        //编辑联系人
        editlinkman(index){
            this.linkdata.name = this.linkarr[index].name;
            this.linkdata.is_main = this.linkarr[index].is_main;
            this.linkdata.position = this.linkarr[index].position;
            this.linkdata.sex = this.linkarr[index].sex;
            this.linkdata.linkarr = this.linkarr[index].linkarr;
            this.linkdata.biaozhi = 'linkmanedit';
            this.linkindex = index;
        },
        //移除联系人
        dellinkman(index){
            this.linkarr.splice(index, 1);
            $('#headeralert').show()
            $('#headeralert p').html('*删除成功' + '<br>')
        },
        //添加联系方式
        addlinkmethod(){
            //还有联系方式值和联系类型id
            if (this.linkdata.linkval && this.linkdata.linkfunid) {
                if (this.linkdata.iseditlianxi > 0 && this.linkdata.iseditlianxi != 'a') {
                    //通过点击编辑，添加的联系方式
                    let lanxieditid = this.linkdata.linkarr[this.linkdata.iseditlianxi]['coattr_id'];//联系类型id
                    if (lanxieditid != this.linkdata.linkfunid) {
                        //编辑的联系方式改变了，就需要判断现在重新添加的类型是否存在语列表页面
                        $.each(this.linkdata.linkarr, (key, value) => {
                            if (value.coattr_id == this.linkdata.linkfunid) {
                                change_mes_type('.modal-body .alert', 3)
                                $('.modal-body .alert').show()
                                $('.modal-body .alert p').html('*编辑的联系方式已经存在' + '<br>');
                                this.linkdata.isex = '2';
                            }
                        });
                        //存在联系方式的重置
                        if (this.linkdata.isex == '2') {
                            this.linkdata.isex = '1';
                            return false;
                        }
                        if (this.linkdata.isex == '1') {
                            //编辑时写的是其他的联系方式
                            this.linkdata.linkarr[this.linkdata.iseditlianxi]['linkname'] = $("#sellinkfun").find("option:selected").text();
                            this.linkdata.linkarr[this.linkdata.iseditlianxi]['coattr_id'] = this.linkdata.linkfunid;
                        }
                    }
                    //无论联系类型id是否改变，更新内容
                    this.linkdata.linkarr[this.linkdata.iseditlianxi]['content'] = this.linkdata.linkval;
                } else {
                    //直接添加联系方式
                    this.listlanxitwo();
                    let isexit = this.linkdata.lianxi_ids.findIndex(item => item == this.linkdata.linkfunid);
                    if (isexit >= 0) {
                        //添加时，添加的联系方式类型，存在列表,覆盖操作
                        $.each(this.linkdata.linkarr, (key, value) => {
                            if (value.coattr_id == this.linkdata.linkfunid) {
                                this.linkdata.linkarr[key]['content'] = this.linkdata.linkval;
                            }
                        });
                    } else {
                        //添加
                        this.linkdata.linkarr.push({
                            id: '',//联系方式id
                            linkname: $("#sellinkfun").find("option:selected").text(),
                            coattr_id: this.linkdata.linkfunid,//联系方式类型id
                            content: this.linkdata.linkval,//联系方式
                        })
                    }
                }
                this.linkdata.isex = '1';
                this.linkdata.iseditlianxi = 'a'
                this.linkdata.linkval = '';
                this.linkdata.linkfunid = '';
            } else {
                change_mes_type('.modal-body .alert', 2)
                $('.modal-body .alert').show()
                $('.modal-body .alert p').html('*数据不完整' + '<br>')
            }
        },
        //获取最新的联系类型id
        listlanxitwo(){
            this.linkdata.lianxi_ids = [];
            this.linkdata.linkarr.forEach((element, index) => {
                this.linkdata.lianxi_ids.push(element.coattr_id)
            })
        },
        //编辑联系方式
        editlinkfun(index){
            this.linkdata.linkval = this.linkdata.linkarr[index].content
            if (this.linkdata.linkarr[index].linkname) {
                this.linkdata.linkfunid = this.linkdata.linkarr[index].coattr_id
            } else {
                this.linkdata.linkfunid = '';
            }
            this.linkdata.iseditlianxi = index;
            this.linkdata.isex = '1';
        },
        //删除联系方式
        dellinkitem(index){
            this.linkdata.linkarr.splice(index, 1);
            this.linkdata.iseditlianxi = 'a';
            this.linkdata.isex = '1';
        },
        //保存联系方式
        addlinkdata(){
            $.ajax({
                url: '/admin/customer/linkaddedit',
                type: 'post',
                data: {
                    name: this.linkdata.name,
                    position: this.linkdata.position,
                    sex: this.linkdata.sex,
                    linkarr: this.linkdata.linkarr,
                    biaozhi: this.linkdata.biaozhi,
                },
                success: (data) => {
                    data = JSON.parse(data)
                    if (data.status != 1) {
                        change_mes_type('.modal-body .alert', data.status)
                        $('.modal-body .alert').show()
                        $('.modal-body .alert p').html('*' + data.msg + '<br>')
                    } else {
                        if (this.linkdata.biaozhi == 'linkmanedit') {
                            //编辑联系人
                            this.linkarr[this.linkindex].name = this.linkdata.name;
                            this.linkarr[this.linkindex].is_main = this.linkdata.is_main;
                            this.linkarr[this.linkindex].sex = this.linkdata.sex;
                            this.linkarr[this.linkindex].sexman = data.sexman;
                            this.linkarr[this.linkindex].linkarr = this.linkdata.linkarr;
                            this.linkarr[this.linkindex].update_at = data.update_at;
                            this.linkarr[this.linkindex].update_date = data.update_date;
                            this.linkarr[this.linkindex].update_id = data.update_id;
                            this.linkarr[this.linkindex].updatename = data.updatename;
                            this.linkarr[this.linkindex].position = this.linkdata.position;
                        } else if (this.linkdata.biaozhi == 'linkmanadd') {
                            //添加联系人
                            this.linkarr.push({
                                id: '',
                                name: this.linkdata.name,
                                is_main: this.linkdata.is_main,
                                sex: this.linkdata.sex,
                                sexman: data.sexman,
                                linkarr: this.linkdata.linkarr,
                                update_at: data.update_at,
                                update_date: data.update_date,
                                update_id: data.update_id,
                                updatename: data.updatename,
                                position: this.linkdata.position,
                            })
                        }
                        change_mes_type('#headeralert', data.status)
                        $('#headeralert').show()
                        $('#linkman_Modal').modal('hide')
                        $('#headeralert p').html('*' + data.msg + '<br>')
                    }
                }
            })
        },
        //添加银行账号
        addbank(){
            this.bankdata.biaozhi = 'bankadd';
        },
        //编辑银行账号
        editbank(index){
            this.bankdata.banks_id = this.bankarr[index].banks_id;
            this.bankdata.bankname = this.bankarr[index].bankname;
            this.bankdata.account_name = this.bankarr[index].account_name;
            this.bankdata.account_num = this.bankarr[index].account_num;
            this.bankdata.is_main = this.bankarr[index].is_main;
            this.bankdata.biaozhi = 'bankedit';
            this.bankindex = index;
        },
        //删除银行账号
        delbank(index){
            this.bankarr.splice(index, 1);
            $('#headeralert').show()
            $('#headeralert p').html('*删除成功' + '<br>')
        },
        //保存银行账号
        addbankdata(){
            $.ajax({
                url: '/admin/customer/bankaddedit',
                type: 'post',
                data: {
                    banks_id: this.bankdata.banks_id,
                    bankname: this.bankdata.bankname,
                    account_name: this.bankdata.account_name,
                    account_num: this.bankdata.account_num,
                    biaozhi: this.bankdata.biaozhi,
                },
                success: (data) => {
                    data = JSON.parse(data)
                    if (data.status != 1) {
                        change_mes_type('.modal-body .alert', data.status)
                        $('.modal-body .alert').show()
                        $('.modal-body .alert p').html('*' + data.msg + '<br>')
                    } else {
                        if (this.bankdata.biaozhi == 'bankadd') {
                            //添加账户
                            this.bankarr.push({
                                id: '',
                                name: data.name,
                                banks_id: this.bankdata.banks_id,
                                bankname: this.bankdata.bankname,
                                account_name: this.bankdata.account_name,
                                account_num: this.bankdata.account_num,
                                is_main: this.bankdata.is_main,
                                update_at: data.update_at,
                                update_date: data.update_date,
                                update_id: data.update_id,
                                updatename: data.updatename,
                            })
                        } else if (this.bankdata.biaozhi == 'bankedit') {
                            //编辑账户
                            this.bankarr[this.bankindex].name = data.name;
                            this.bankarr[this.bankindex].banks_id = this.bankdata.banks_id;
                            this.bankarr[this.bankindex].bankname = this.bankdata.bankname;
                            this.bankarr[this.bankindex].account_name = this.bankdata.account_name;
                            this.bankarr[this.bankindex].account_num = this.bankdata.account_num;
                            this.bankarr[this.bankindex].is_main = this.bankdata.is_main;
                            this.bankarr[this.bankindex].update_at = data.update_at;
                            this.bankarr[this.bankindex].update_date = data.update_date;
                            this.bankarr[this.bankindex].update_id = data.update_id;
                            this.bankarr[this.bankindex].updatename = data.updatename;
                        }
                        change_mes_type('#headeralert', data.status)
                        $('#headeralert').show()
                        $('#bank_Modal').modal('hide')
                        $('#headeralert p').html('*' + data.msg + '<br>')
                    }
                }
            })
        },
        //添加分公司
        addbranch(){
            if ($('#country_id').val()) {
                //有公司id
                this.selchangebranchfun('provinces', $('#country_id').val());
                this.branchdata.country_id = $('#country_id').val();
            }
            this.branchdata.biaozhi = 'branchadd';
        },
        //编辑分公司
        editbranch(index){
            this.branchdata.name = this.brancharr[index].name;
            this.branchdata.lock = this.brancharr[index].lock;

            this.branchdata.country_id = this.brancharr[index].country_id;
            var getbreach = async () => {
                await this.selchangebranchfun('provinces', this.brancharr[index].country_id);
                this.branchdata.province_id = this.brancharr[index].province_id;
                await this.selchangebranchfun('city', this.brancharr[index].province_id);
                this.branchdata.city_id = this.brancharr[index].city_id;
                await this.selchangebranchfun('town', this.brancharr[index].city_id)
                this.branchdata.town_id = this.brancharr[index].town_id;
            }
            getbreach()
            this.branchdata.addr = this.brancharr[index].addr;
            this.branchdata.zipcode = this.brancharr[index].zipcode;
            this.branchdata.works = this.brancharr[index].works;
            this.branchdata.regno = this.brancharr[index].regno;
            this.branchdata.taxno = this.brancharr[index].taxno;
            this.branchdata.biaozhi = 'branchedit';
            this.branchindex = index;
        },
        //删除分公司
        delbranch(index){
            this.brancharr.splice(index, 1);
            $('#headeralert').show()
            $('#headeralert p').html('*删除成功' + '<br>')
        },
        //点击锁定
        lockbut(){
            if (this.branchdata.lock == '1' || this.branchdata.lock == true) {
                this.branchdata.lock = '0';
            } else {
                this.branchdata.lock = '1';
            }
        },
        //保存分公司
        addbranchdata(){
            $.ajax({
                url: '/admin/customer/branchaddedit',
                type: 'post',
                data: {
                    name: this.branchdata.name,
                    country_id: this.branchdata.country_id,
                    province_id: this.branchdata.province_id,
                    city_id: this.branchdata.city_id,
                    town_id: this.branchdata.town_id,
                    addr: this.branchdata.addr,
                    works: this.branchdata.works,
                    biaozhi: this.branchdata.biaozhi,
                    lang: this.lang
                },
                success: (data) => {
                    data = JSON.parse(data)
                    if (data.status != 1) {
                        change_mes_type('.modal-body .alert', data.status)
                        $('.modal-body .alert').show()
                        $('.modal-body .alert p').html('*' + data.msg + '<br>')
                    } else {
                        if (this.branchdata.biaozhi == 'branchadd') {
                            //添加分公司
                            this.brancharr.push({
                                id: '',
                                name: this.branchdata.name,
                                lock: this.branchdata.lock,
                                country_id: this.branchdata.country_id,
                                province_id: this.branchdata.province_id,
                                city_id: this.branchdata.city_id,
                                town_id: this.branchdata.town_id,
                                address: data.address,
                                addr: this.branchdata.addr,
                                worksnum: data.worksnum,
                                works: this.branchdata.works,
                                regno: this.branchdata.regno,
                                taxno: this.branchdata.taxno,
                                zipcode: this.branchdata.zipcode,
                                update_at: data.update_at,
                                update_date: data.update_date,
                                update_id: data.update_id,
                                updatename: data.updatename,
                            });
                        } else if (this.branchdata.biaozhi == 'branchedit') {
                            //编辑分公司
                            this.brancharr[this.branchindex].name = this.branchdata.name;
                            this.brancharr[this.branchindex].lock = this.branchdata.lock;
                            this.brancharr[this.branchindex].country_id = this.branchdata.country_id;
                            this.brancharr[this.branchindex].province_id = this.branchdata.province_id;
                            this.brancharr[this.branchindex].city_id = this.branchdata.city_id;
                            this.brancharr[this.branchindex].town_id = this.branchdata.town_id;
                            this.brancharr[this.branchindex].address = data.address;
                            this.brancharr[this.branchindex].addr = this.branchdata.addr;
                            this.brancharr[this.branchindex].worksnum = data.worksnum;
                            this.brancharr[this.branchindex].works = this.branchdata.works;
                            this.brancharr[this.branchindex].regno = this.branchdata.regno;
                            this.brancharr[this.branchindex].taxno = this.branchdata.taxno;
                            this.brancharr[this.branchindex].zipcode = this.branchdata.zipcode;
                            this.brancharr[this.branchindex].update_at = data.update_at;
                            this.brancharr[this.branchindex].update_date = data.update_date;
                            this.brancharr[this.branchindex].update_id = data.update_id;
                            this.brancharr[this.branchindex].updatename = data.updatename;
                        }
                        change_mes_type('#headeralert', data.status)
                        $('#headeralert').show()
                        $('#branch_editModal').modal('hide')
                        $('#headeralert p').html('*' + data.msg + '<br>')
                    }
                }
            })
        },
        //添加风评
        addevaluate(){
            this.evaluatedata.biaozhi = 'evaluateadd';
        },
        //编辑风评
        editevaluate(index){
            this.evaluatedata.biaozhi = 'evaluateedit';
            this.evaluateindex = index;
            this.evaluatedata.comment = this.evaluatearr[index].comment;
            this.evaluatedata.score = this.evaluatearr[index].score;
        },
        //删除风评
        delevaluate(index){
            this.evaluatearr.splice(index, 1);
            $('#headeralert').show()
            $('#headeralert p').html('*删除成功' + '<br>')
        },
        //保存公司风评
        addevaluatedata(){
            $.ajax({
                url: '/admin/customer/evaluateaddedit',
                type: 'post',
                data: {
                    biaozhi: this.evaluatedata.biaozhi,
                    comment: this.evaluatedata.comment,
                },
                success: (data) => {
                    data = JSON.parse(data)
                    if (data.status != 1) {
                        change_mes_type('.modal-body .alert', data.status)
                        $('.modal-body .alert').show()
                        $('.modal-body .alert p').html('*' + data.msg + '<br>')
                    } else {
                        if (this.evaluatedata.biaozhi == 'evaluateadd') {
                            //添加风评
                            this.evaluatearr.push({
                                id: '',
                                comment: this.evaluatedata.comment,
                                score: this.evaluatedata.score,
                                update_at: data.update_at,
                                update_date: data.update_date,
                                update_id: data.update_id,
                                updatename: data.updatename,
                            });
                        } else if (this.evaluatedata.biaozhi == 'evaluateedit') {
                            //编辑风评
                            this.evaluatearr[this.evaluateindex].comment = this.evaluatedata.comment;
                            this.evaluatearr[this.evaluateindex].score = this.evaluatedata.score;
                            this.evaluatearr[this.evaluateindex].update_at = data.update_at;
                            this.evaluatearr[this.evaluateindex].update_date = data.update_date;
                            this.evaluatearr[this.evaluateindex].update_id = data.update_id;
                            this.evaluatearr[this.evaluateindex].updatename = data.updatename;
                        }
                        change_mes_type('#headeralert', data.status)
                        $('#headeralert').show()
                        $('#co_evaluate_Modal').modal('hide')
                        $('#headeralert p').html('*' + data.msg + '<br>')
                    }
                }
            })
        }
    }
})
$("#linkman_Modal").on("hidden.bs.modal", function () {
    $(this).removeData("bs.modal");
    $(document).unbind('keydown')
});
$("#bank_Modal").on("hidden.bs.modal", function () {
    $(this).removeData("bs.modal");
    $(document).unbind('keydown')
});
$("#branch_editModal").on("hidden.bs.modal", function () {
    $(this).removeData("bs.modal");
    $(document).unbind('keydown')
});
$("#co_evaluate_Modal").on("hidden.bs.modal", function () {
    $(this).removeData("bs.modal");
    $(document).unbind('keydown')
});